﻿// <copyright file="SupportedClaim.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Barry Dorrans</author>
// <email>barryd@idunno.org</email>
// <date>2008-06-14</date>
// <summary>Represents the an supported claim configuration element.</summary>

namespace SharpSTS.Configuration
{
    using System.Configuration;

    /// <summary>
    /// A supported claim configuration element.
    /// </summary>
    public sealed class SupportedClaim : ConfigurationElement
    {
        #region Configuration Key Names
        /// <summary>
        /// The attribute name for the URI value.
        /// </summary>
        private const string UriConfigurationKey = @"uri";

        /// <summary>
        /// The attribute name for the description value.
        /// </summary>
        private const string DescriptionConfigurationKey = @"description";
        
        /// <summary>
        /// The attribute name for the identity claim flag.
        /// </summary>
        private const string IdentityClaimConfigurationKey = @"identityClaim";

        /// <summary>
        /// The attribute name for the SAML name identifier type of the claim.
        /// </summary>
        private const string TypeConfigurationKey = @"type";
        #endregion

        /// <summary>
        /// Gets or sets the URI of the supported claim.
        /// </summary>
        /// <value>The URI of the supported claim.</value>
        [System.Diagnostics.CodeAnalysis.SuppressMessage(
            "Microsoft.Design",
            "CA1056:UriPropertiesShouldNotBeStrings",
            Justification = "The URI comes from the configuration settings, and may also be in urn format or null.")]
        [ConfigurationProperty(UriConfigurationKey, DefaultValue = "", IsKey = true, IsRequired = true)]
        public string Uri
        {
            get
            {
                return ((string)(base[UriConfigurationKey]));
            }

            set
            {
                base[UriConfigurationKey] = value;
            }
        }

        /// <summary>
        /// Gets or sets the description of the supported claim.
        /// </summary>
        /// <value>The description of the supported claim.</value>
        [ConfigurationProperty(DescriptionConfigurationKey, DefaultValue = "", IsKey = false, IsRequired = false)]
        public string Description
        {
            get
            {
                return ((string)(base[DescriptionConfigurationKey]));
            }

            set
            {
                base[DescriptionConfigurationKey] = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this claim is the identity claim.
        /// </summary>
        /// <value>
        /// A flag which indicates if this claim is the identity claim.
        /// </value>
        [ConfigurationProperty(IdentityClaimConfigurationKey, DefaultValue = false, IsKey = false, IsRequired = false)]
        public bool IdentityClaim
        {
            get
            {
                return ((bool) base[IdentityClaimConfigurationKey]);
            }
            
            set
            {
                base[IdentityClaimConfigurationKey] = value;
            }
        }

        /// <summary>
        /// Gets or sets the SAML name identifier type for the claim.
        /// </summary>
        /// <value>The the SAML name identifier type for the claim.</value>
        /// <remarks>This value is only used if a claim is marked as the IdentityClaim by specifing IdentityClaim="true".</remarks>
        [ConfigurationProperty(TypeConfigurationKey, DefaultValue = SamlNameIdentifier.Unspecified, IsKey = false, IsRequired = false)]
        public SamlNameIdentifier IdentifierType
        {
            get
            {
                return ((SamlNameIdentifier) base[TypeConfigurationKey]);
            }
            
            set
            {
                base[TypeConfigurationKey] = value;
            }
        }
    }
}
